package com.badger.spring.cloud.alibaba.provider.config;

import javax.servlet.http.HttpServletRequest;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import lombok.extern.slf4j.Slf4j;

/**
 * 全局异常捕获
 * @author liqi
 */
@Slf4j
@ControllerAdvice
public class WholeExceptionHandler {

    /**
     * 系统错误
     * @param req
     * @param e
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public String systemException(HttpServletRequest req, Exception e) {
        log.error(e.getMessage());
        e.printStackTrace();
        return e.getMessage();
    }

}
